/**
 * @author LKQ
 * @date 2021/12/27 14:44
 * @description 位移运算
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.concatenatedBinary(12);
    }

    public int concatenatedBinary(int n) {
        long res = 0;
        int M = 1_000_000_007;
        int shift = 0;
        for (int i = 1; i <= n; i++) {
            if ((i & (i - 1)) == 0) {
                // i & i-1 判断 i 是否为2的幂。
                shift++;
            }
            // 左移的优先级低，需要括号先算
            res = ((res << shift) % M + i) % M;
        }
        return (int)res;
    }
}
